package com.pg.controller.sy;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pg.entity.dd.EipSalesOrder;
import com.pg.entity.dd.EipWorkOrder;
import com.pg.entity.sy.EipLightningImpulse;
import com.pg.service.EipLightningImpulseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 雷电冲击试验前端控制器
 * </p>
 *
 * @author likl
 * @since 2020-07-22
 */
@Api(tags = "雷电冲击试验")
@RestController
@RequestMapping("/eipLightningImpulse")
public class EipLightningImpulseController extends JeecgController<EipLightningImpulse, EipLightningImpulseService> {

    @Autowired
    private EipLightningImpulseService eipLightningImpulseService;

    /**
     * 添加 雷电冲击试验
     *
     * @param eipLightningImpulse 雷电冲击试验
     * @return 是否成功
     */
    @ApiOperation("添加 雷电冲击试验")
    @AutoLog(value = "添加 雷电冲击试验")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody EipLightningImpulse eipLightningImpulse) {
        eipLightningImpulse.setPuid(UUID.randomUUID().toString());
        eipLightningImpulseService.save(eipLightningImpulse);
        return Result.ok("添加成功！");
    }

    /**
     * 编辑 雷电冲击试验
     *
     * @param eipLightningImpulse 雷电冲击试验
     * @return 是否成功
     */
    @ApiOperation("编辑 雷电冲击试验")
    @AutoLog(value = "编辑 雷电冲击试验")
    @PutMapping(value = "/edit")
    public Result<?> edit(@RequestBody EipLightningImpulse eipLightningImpulse) {
        eipLightningImpulse.setPuid(UUID.randomUUID().toString());
        eipLightningImpulseService.updateById(eipLightningImpulse);
        return Result.ok("编辑成功!");
    }

    /**
     * 通过id删除 雷电冲击试验
     *
     * @param id 全库唯一码
     * @return 是否成功
     */
    @ApiOperation("通过id删除 雷电冲击试验")
    @AutoLog(value = "通过id删除 雷电冲击试验")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
        eipLightningImpulseService.removeById(id);
        return Result.ok("删除成功!");
    }

    /**
     * 批量删除 雷电冲击试验
     *
     * @param ids 全库唯一码集合
     * @return 是否成功
     */
    @ApiOperation("批量删除 雷电冲击试验")
    @AutoLog(value = "批量删除 雷电冲击试验")
    @DeleteMapping(value = "/deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.eipLightningImpulseService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.ok("批量删除成功!");
    }

    /**
     * 通过id查询 雷电冲击试验
     *
     * @param id 全库唯一码
     * @return 雷电冲击试验数据
     */
    @ApiOperation("通过id查询 雷电冲击试验")
    @AutoLog(value = "通过id查询 雷电冲击试验")
    @GetMapping(value = "/queryById")
    public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
        EipLightningImpulse eipLightningImpulse = eipLightningImpulseService.getById(id);
        if (eipLightningImpulse == null) {
            return Result.error("未找到对应数据");
        }
        return Result.ok(eipLightningImpulse);
    }

    /**
     * 分页列表查询 雷电冲击试验
     *
     * @param eipLightningImpulse 雷电冲击试验
     * @param startCheckTime      起始时间
     * @param endCheckTime        结束时间
     * @param pageNo              起始页
     * @param pageSize            每页页数
     * @param req                 参数
     * @return 分页数据
     */
    @ApiOperation("分页列表查询 雷电冲击试验")
    @AutoLog(value = "QueryExport")
    @RequestMapping(method = RequestMethod.GET, value = "/list")
    public Result<?> selectForList(EipLightningImpulse eipLightningImpulse,
                                   @RequestParam(name = "startCheckTime", defaultValue = "") @DateTimeFormat(pattern = "yyyy-MM-dd") Date startCheckTime,
                                   @RequestParam(name = "endCheckTime", defaultValue = "") @DateTimeFormat(pattern = "yyyy-MM-dd") Date endCheckTime,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {
        Page<EipLightningImpulse> page = new Page<>(pageNo, pageSize);
        IPage<EipLightningImpulse> pageList = eipLightningImpulseService.selectForList(page, eipLightningImpulse, startCheckTime, endCheckTime);
        return Result.ok(pageList);
    }

    /**
     * 通过excel导入数据 雷电冲击试验
     *
     * @param request  参数
     * @param response 响应
     * @return 是否成功
     */
    @ApiOperation("通过excel导入数据 雷电冲击试验")
    @AutoLog(value = "通过excel导入数据 雷电冲击试验")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, EipLightningImpulse.class);
    }

    /**
     * 导出excel 雷电冲击试验
     *
     * @param request             参数
     * @param eipLightningImpulse 雷电冲击试验
     */
    @ApiOperation("导出excel 雷电冲击试验")
    @AutoLog(value = "QueryExport")
    @RequestMapping(method = RequestMethod.GET,value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, EipLightningImpulse eipLightningImpulse) {
        return super.exportXls(request, eipLightningImpulse, EipLightningImpulse.class, "eip_lightning_impulse");
    }

}
